<template>
  <div class="goodsFenleiCreate">
    <el-card class="box-card">
      <!-- 头部 -->
      <div slot="header" class="clearfix header">
        <span>角色创建</span>
        <el-button type="primary" round @click="backFn">返回</el-button>
      </div>
      <!-- end---------------- -->

      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="角色名称" prop="type_name">
          <el-input
            type="password"
            v-model="ruleForm.type_name"
            autocomplete="off"
          >
          </el-input>
        </el-form-item>

        <el-form-item label="角色描述" prop="type_name">
          <el-input
            type="password"
            v-model="ruleForm.type_name"
            autocomplete="off"
          >
          </el-input>
        </el-form-item>

        <!-- 按钮 -->
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >提交</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
        <!-- ------------------------------end -->
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //表单添加数据
      ruleForm: {
        type_name: ""
      },
      rules: {
        //键 ruleForm里面的键
        //值 数组里面是一个个对象 赋值
        type_name: [
          { required: true, message: "请输入类型名称", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    //提交
    submitForm(refName) {
      //this.$refs[formName].validate((valid) => {}
      this.$refs[refName].validate(isSuccess => {
        if (isSuccess) {
          this.$message.success("发送异步请求");
        }
      });
    },
    //重置
    resetForm(refName) {
      //  this.$refs[formName].resetFields();
      this.$refs[refName].resetFields();
    },
    //返回
    backFn() {
      this.$router.push({ path: "/roles" });
    }
  }
};
</script>

<style lang="scss" scoped>
.goodsFenleiCreate {
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
